﻿using UnityEngine;

namespace Vosvek.ProjectRogue
{

    /// <summary>
    /// The GameContext is the only singleton for this app. If other singletons
    /// are necessary, call them Managers, and add and initialise them as
    /// public/composite variables.
    /// </summary>
    public class GameContext : MonoBehaviour
    {
        public SoundManager SoundManager { get; private set; }
        public ViewManager ViewManager { get; private set; }
        public GameManager GameManager { get; private set; }

        public static GameContext Instance { get; private set; }

        // Necessary due to old .NET version.
        void Init()
        {
            SoundManager = new SoundManager();
            ViewManager = new ViewManager();
            GameManager = new GameManager();
        }

        void Awake()
        {
            // If there is no instance, set up singleton.
            if (Instance == null)
            {
                Instance = this;
                DontDestroyOnLoad(this);
                Init();
            }
            // Otherwise, destroy the clones!
            else
            {
                Destroy(this);
            }
        }
    }

}
